package geppetto.phraseProbability.smoothing;

import geppetto.phraseProbability.PhraseProbabilityCalculator;
import geppetto.phraseTable.PhraseTable;
import geppetto.phraseTable.phrase.Phrase;

public class DiscountSmoothingProbabilityCalc implements PhraseProbabilityCalculator{

	public DiscountFunction _discountFunc;
	public PhraseProbabilityCalculator _smoothingDistribution;	

	public DiscountSmoothingProbabilityCalc(DiscountFunction discountFunc,
			PhraseProbabilityCalculator distribution) {
		super();
		this._discountFunc = discountFunc;
		_smoothingDistribution = distribution;
	}

	public double calculateProbablity(PhraseTable phraseTable, Phrase p,
			int sourceLength, int targetLength) {
		
		/*double sourceSum = phraseTable.getSumForSource(p._sourcePhraseID, sourceLength);
		double sourceCount = phraseTable.getCountForSource(p._sourcePhraseID, sourceLength);
		double discount = _discountFunc.getDiscount(phraseTable, p);

		double mainProbability = Math.max((p.getCounts() - discount) / sourceSum,0);
		double smoothingFunctionCoef = discount * sourceCount / sourceSum;
		
		double smoothingProbability = _smoothingDistribution.calculateProbablity(phraseTable, p, sourceLength, targetLength);
		
		return mainProbability + smoothingFunctionCoef * smoothingProbability;*/
		return 0;
	}

	public double calculateProbablityReverse(PhraseTable phraseTable, Phrase p,
			int sourceLength, int targetLength) {
		/*double targetSum = phraseTable.getSumForTarget(p._targetPhraseID, targetLength);
		double targetCount = phraseTable.getCountForTarget(p._targetPhraseID, targetLength);	
		double discount = _discountFunc.getDiscount(phraseTable, p);
		
		double mainProbability = Math.max((p.getCounts() - discount) / targetSum,0);		
		double smoothingFunctionCoef = discount * targetCount / targetSum;

		double smoothingProbability = _smoothingDistribution.calculateProbablityReverse(phraseTable, p, sourceLength, targetLength);

		//System.out.println(mainProbability + "\t" + smoothingFunctionCoef + "\t" + "\t" +  smoothingProbability + "\t" + p.getSourceString(phraseTable._corpus, phraseTable._sourcePhrasesVocab, phraseTable._targetPhrasesVocab) + "\t" + p.getTargetString(phraseTable._corpus, phraseTable._sourcePhrasesVocab, phraseTable._targetPhrasesVocab));
		return mainProbability + smoothingFunctionCoef * smoothingProbability;*/
		return 0;

	}
/*
	public double calculateProbablityReverse(PhraseTable phraseTable, int source_id, int target_id,
			int sourceLength, int targetLength) {
		Phrase p = phraseTable.getPhrase(source_id, target_id, sourceLength, targetLength);
		if(p != null){
			return calculateProbablityReverse(phraseTable, p, sourceLength, targetLength);
		}
		else{
			double targetSum = phraseTable.getSumForTarget(source_id, targetLength);
			double targetCount = phraseTable.getCountForTarget(target_id, targetLength);
			double discount = _discountFunc.getDiscount(phraseTable, new Phrase(source_id,target_id,0));
			
			double mainProbability = Math.max((p.getCounts() - discount) / targetSum,0);
			
			double smoothingFunctionCoef = discount * targetCount / targetSum;

			double smoothingProbability = _smoothingDistribution.calculateProbablityReverse(phraseTable, p, sourceLength, targetLength);
			
			return mainProbability + smoothingFunctionCoef * smoothingProbability;
		}
	}*/
}
